var express = require('express');
var router = express.Router();
var http = require('http');
// 轮播图的路由
router.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
})
router.get('/lunbo', function(req, resl, next) {
    http.get('http://m.maizuo.com/v4/api/billboard/home?__t=1495518126859', function(res) {
        var str = '';
        res.on('data', function(chunk) {
            str += chunk;
        });
        res.on('end', function() {
            //请求到的数据
            resl.send(str)
          
        });
        res.on('error', function(err) {
            console.log(err)
        })
    })
});
//正在上映
router.get('/zhengzai', function(req, resl, next) {
    http.get('http://m.maizuo.com/v4/api/film/now-playing?__t=1495518126864&page=1&count=5', function(res) {
        var str = '';
        res.on('data', function(chunk) {
            str += chunk;
        });
        res.on('end', function() {
            //请求到的数据
            resl.send(str)
          
        });
        res.on('error', function(err) {
            console.log(err)
        })
    })
});
//即将上映 
router.get('/jijiang', function(req, resl, next) {
    http.get('http://m.maizuo.com/v4/api/film/coming-soon?__t=1495518126867&page=1&count=3', function(res) {
        var str = '';
        res.on('data', function(chunk) {
            str += chunk;
        });
        res.on('end', function() {
            //请求到的数据
            resl.send(str)
          
        });
        res.on('error', function(err) {
            console.log(err)
        })
    })
});
//电影详情
router.get('/details',function(req,resl,next){
    var url ='http://m.maizuo.com/v4/api/film/'+req.query.id+'?__t='+req.query.time;
    console.log(url)
    http.get(url,function(res){
        var str=''
        res.on('data',function(chunk){
            str+= chunk;
        });
        res.on('end',function(){
            resl.end(str)
        });
        res.on('error',function(err){
            console.log(err)
        })
    })
})
module.exports = router;
